﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Axelerate.Silverlight3D.Media.Media3D;

namespace VS.Infrastructure.Controls
{
    public class TagCloudItem : ContentControl
    {
        #region Fields
        internal Point3D _centerPoint;
        private ScaleTransform _scaleTransform = new ScaleTransform();
        #endregion

        #region Properties
        #endregion

        #region Methods
        public TagCloudItem(double x, double y, double z)
            : this()
        {
            _centerPoint = new Point3D(x, y, z);
        }

        public TagCloudItem()
        {
            this.RenderTransformOrigin = new Point(0.5, 0.5);
            this.RenderTransform = _scaleTransform;
        }

        public string Text { get; set; }

        public void Redraw(double xOffset, double yOffset)
        {
            double zoom = 0.01;
            double posZ = _centerPoint.Z + 200;
            double scale = posZ * zoom - 0.5;
            
            _scaleTransform.ScaleX = scale;
            _scaleTransform.ScaleY = scale;

            double alpha = scale / 3;
            if (alpha > 1)
                alpha = 1;
            if (alpha < 0)
                alpha = 0.25;

            this.Opacity = alpha;

            double x = _centerPoint.X + xOffset - (DesiredSize.Width / 2);
            double y = _centerPoint.Y + yOffset - (DesiredSize.Height / 2);
            Arrange(new Rect(x, y, DesiredSize.Width, DesiredSize.Height));

            Canvas.SetZIndex(this, Convert.ToInt32(_centerPoint.Z));
        }

        #endregion
    }

}
